//
// Created by xili on 2024/8/28 21:21.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    bool areAlmostEqual(string s1, string s2) {
        int n = s1.size();
        int cnt = 0;
        int x = -1, y = -1;
        for (int i = 0; i < n; i++) {
            if (s1[i] != s2[i]) {
                if (x == -1) {
                    x = i;
                    cnt++;
                } else {
                    y = i;
                    cnt++;
                }
            }
        }
        if (cnt == 2) {
            swap(s1[x], s2[y]);
        }
        return s1 == s2;
    }
};